/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jFParente.java
 *
 * Created on 21/06/2012, 21:52:12
 */
package sccpa;

import java.awt.Component;
import java.awt.EventQueue;
import java.beans.Beans;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.RollbackException;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;

/**
 *
 * @author admin
 */
public class jFParente extends JPanel {
    
    public jFParente() {
        initComponents();
        if (!Beans.isDesignTime()) {
            entityManager.getTransaction().begin();
        }
        setParente();
    }

private void setParente(){
    Alunos oAluno = new Alunos();
    oAluno.setCodAluno(jFAluno.codAluno);
    composicaoFamiliar1.setCodAluno(oAluno);
    query = java.beans.Beans.isDesignTime() ? null : entityManager.createNamedQuery("ComposicaoFamiliar.findByCodAluno");
    query.setParameter("codAluno", oAluno);
    
    java.util.Collection data = query.getResultList();
    
    list.clear();
    list.addAll(data);
    
}
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sccpa.SCCPAApp.class).getContext().getResourceMap(jFParente.class);
        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory(resourceMap.getString("entityManager.persistenceUnit")).createEntityManager(); // NOI18N
        query = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery(resourceMap.getString("query.query")); // NOI18N
        list = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(query.getResultList());
        composicaoFamiliar1 = new sccpa.ComposicaoFamiliar();
        alunosQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT a FROM Alunos a");
        alunosList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : alunosQuery.getResultList();
        pessoasQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT p FROM Pessoas p");
        pessoasList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : pessoasQuery.getResultList();
        jToolBar1 = new javax.swing.JToolBar();
        newButton = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        refreshButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jComboBox2 = new javax.swing.JComboBox();
        jComboBox3 = new javax.swing.JComboBox();
        numeroPessoasFamiliaField = new javax.swing.JTextField();
        rendaFamiliarAntesField = new javax.swing.JTextField();
        rendaFamiliarDepoisField = new javax.swing.JTextField();
        jComboBox1 = new javax.swing.JComboBox();
        masterScrollPane = new javax.swing.JScrollPane();
        masterTable = new javax.swing.JTable();
        numeroPessoasFamiliaLabel = new javax.swing.JLabel();
        historicoFamiliarLabel = new javax.swing.JLabel();
        parentescoLabel = new javax.swing.JLabel();
        codPessoaLabel = new javax.swing.JLabel();
        codAlunoLabel = new javax.swing.JLabel();
        rendaFamiliarDepoisLabel = new javax.swing.JLabel();
        rendaFamiliarAntesLabel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jComboBox4 = new javax.swing.JComboBox();

        FormListener formListener = new FormListener();

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.codAluno}"), composicaoFamiliar1, org.jdesktop.beansbinding.BeanProperty.create("codAluno"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.codComposicaoFamiliar}"), composicaoFamiliar1, org.jdesktop.beansbinding.BeanProperty.create("codComposicaoFamiliar"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.codPessoa}"), composicaoFamiliar1, org.jdesktop.beansbinding.BeanProperty.create("codPessoa"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.historicoFamiliar}"), composicaoFamiliar1, org.jdesktop.beansbinding.BeanProperty.create("historicoFamiliar"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.numeroPessoasFamilia}"), composicaoFamiliar1, org.jdesktop.beansbinding.BeanProperty.create("numeroPessoasFamilia"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.parentesco}"), composicaoFamiliar1, org.jdesktop.beansbinding.BeanProperty.create("parentesco"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.rendaFamiliarAntes}"), composicaoFamiliar1, org.jdesktop.beansbinding.BeanProperty.create("rendaFamiliarAntes"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.rendaFamiliarDepois}"), composicaoFamiliar1, org.jdesktop.beansbinding.BeanProperty.create("rendaFamiliarDepois"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.responsavel}"), composicaoFamiliar1, org.jdesktop.beansbinding.BeanProperty.create("responsavel"));
        bindingGroup.addBinding(binding);

        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setName("Form"); // NOI18N

        jToolBar1.setBackground(resourceMap.getColor("jToolBar1.background")); // NOI18N
        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        newButton.setBackground(resourceMap.getColor("newButton.background")); // NOI18N
        newButton.setIcon(resourceMap.getIcon("newButton.icon")); // NOI18N
        newButton.setText(resourceMap.getString("newButton.text")); // NOI18N
        newButton.setName("newButton"); // NOI18N
        newButton.addActionListener(formListener);
        jToolBar1.add(newButton);

        deleteButton.setBackground(resourceMap.getColor("deleteButton.background")); // NOI18N
        deleteButton.setText(resourceMap.getString("deleteButton.text")); // NOI18N
        deleteButton.setName("deleteButton"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), deleteButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        deleteButton.addActionListener(formListener);
        jToolBar1.add(deleteButton);

        refreshButton.setBackground(resourceMap.getColor("refreshButton.background")); // NOI18N
        refreshButton.setIcon(resourceMap.getIcon("refreshButton.icon")); // NOI18N
        refreshButton.setText(resourceMap.getString("refreshButton.text")); // NOI18N
        refreshButton.setName("refreshButton"); // NOI18N
        refreshButton.addActionListener(formListener);
        jToolBar1.add(refreshButton);

        saveButton.setBackground(resourceMap.getColor("saveButton.background")); // NOI18N
        saveButton.setIcon(resourceMap.getIcon("saveButton.icon")); // NOI18N
        saveButton.setText(resourceMap.getString("saveButton.text")); // NOI18N
        saveButton.setName("saveButton"); // NOI18N
        saveButton.addActionListener(formListener);
        jToolBar1.add(saveButton);

        jPanel1.setBackground(resourceMap.getColor("jPanel1.background")); // NOI18N
        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel1.setName("jPanel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setName("jTextArea1"); // NOI18N

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, composicaoFamiliar1, org.jdesktop.beansbinding.ELProperty.create("${historicoFamiliar}"), jTextArea1, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jScrollPane1.setViewportView(jTextArea1);

        jComboBox2.setName("jComboBox2"); // NOI18N
        jComboBox2.setRenderer(new DefaultListCellRenderer(){
            @Override
            public Component getListCellRendererComponent( 
                JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                super.getListCellRendererComponent (list, value, index, isSelected, cellHasFocus);
                if (value instanceof Pessoas) {
                    Pessoas mec = (Pessoas)value;
                    setText(mec.getPessoa());
                }
                return this;
            }
        }
    );

    org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, pessoasList, jComboBox2);
    bindingGroup.addBinding(jComboBoxBinding);
    binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, composicaoFamiliar1, org.jdesktop.beansbinding.ELProperty.create("${codPessoa}"), jComboBox2, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
    bindingGroup.addBinding(binding);

    jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Pai", "Mãe", "Avô(ó)", "Bisavô(ó)", "Neto(a)", "Bisneto(a)", "Filho(a)", "Tio(a)", "Irmão(ã)", "Primo(a),", "Sobrinho(a)", "Conjugê" }));
    jComboBox3.setName("jComboBox3"); // NOI18N

    binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, composicaoFamiliar1, org.jdesktop.beansbinding.ELProperty.create("${parentesco}"), jComboBox3, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
    bindingGroup.addBinding(binding);

    numeroPessoasFamiliaField.setName("numeroPessoasFamiliaField"); // NOI18N

    binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, composicaoFamiliar1, org.jdesktop.beansbinding.ELProperty.create("${numeroPessoasFamilia}"), numeroPessoasFamiliaField, org.jdesktop.beansbinding.BeanProperty.create("text"));
    binding.setSourceUnreadableValue(null);
    bindingGroup.addBinding(binding);
    binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), numeroPessoasFamiliaField, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
    bindingGroup.addBinding(binding);

    rendaFamiliarAntesField.setName("rendaFamiliarAntesField"); // NOI18N

    binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, composicaoFamiliar1, org.jdesktop.beansbinding.ELProperty.create("${rendaFamiliarAntes}"), rendaFamiliarAntesField, org.jdesktop.beansbinding.BeanProperty.create("text"));
    binding.setSourceUnreadableValue(null);
    bindingGroup.addBinding(binding);
    binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), rendaFamiliarAntesField, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
    bindingGroup.addBinding(binding);

    rendaFamiliarDepoisField.setName("rendaFamiliarDepoisField"); // NOI18N

    binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, composicaoFamiliar1, org.jdesktop.beansbinding.ELProperty.create("${rendaFamiliarDepois}"), rendaFamiliarDepoisField, org.jdesktop.beansbinding.BeanProperty.create("text"));
    binding.setSourceUnreadableValue(null);
    bindingGroup.addBinding(binding);
    binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), rendaFamiliarDepoisField, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
    bindingGroup.addBinding(binding);

    jComboBox1.setName("jComboBox1"); // NOI18N
    jComboBox1.setRenderer(new DefaultListCellRenderer(){
        @Override
        public Component getListCellRendererComponent( 
            JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent (list, value, index, isSelected, cellHasFocus);
            if (value instanceof Alunos) {
                Alunos mec = (Alunos)value;
                setText(mec.getAluno());
            }
            return this;
        }
    }
    );

    jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, alunosList, jComboBox1);
    bindingGroup.addBinding(jComboBoxBinding);
    binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, composicaoFamiliar1, org.jdesktop.beansbinding.ELProperty.create("${codAluno}"), jComboBox1, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
    bindingGroup.addBinding(binding);

    masterScrollPane.setName("masterScrollPane"); // NOI18N

    masterTable.setName("masterTable"); // NOI18N

    org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, list, masterTable);
    org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${codComposicaoFamiliar}"));
    columnBinding.setColumnName("Cod Composicao Familiar");
    columnBinding.setColumnClass(Integer.class);
    columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${codPessoa.pessoa}"));
    columnBinding.setColumnName("Cod Pessoa.pessoa");
    columnBinding.setColumnClass(String.class);
    columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${parentesco}"));
    columnBinding.setColumnName("Parentesco");
    columnBinding.setColumnClass(String.class);
    bindingGroup.addBinding(jTableBinding);
    jTableBinding.bind();
    masterScrollPane.setViewportView(masterTable);
    masterTable.getColumnModel().getColumn(0).setMinWidth(50);
    masterTable.getColumnModel().getColumn(0).setMaxWidth(50);
    masterTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("masterTable.columnModel.title0")); // NOI18N
    masterTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("masterTable.columnModel.title2")); // NOI18N
    masterTable.getColumnModel().getColumn(2).setMinWidth(100);
    masterTable.getColumnModel().getColumn(2).setMaxWidth(100);
    masterTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("masterTable.columnModel.title3")); // NOI18N

    numeroPessoasFamiliaLabel.setText(resourceMap.getString("numeroPessoasFamiliaLabel.text")); // NOI18N
    numeroPessoasFamiliaLabel.setName("numeroPessoasFamiliaLabel"); // NOI18N

    historicoFamiliarLabel.setText(resourceMap.getString("historicoFamiliarLabel.text")); // NOI18N
    historicoFamiliarLabel.setName("historicoFamiliarLabel"); // NOI18N

    parentescoLabel.setText(resourceMap.getString("parentescoLabel.text")); // NOI18N
    parentescoLabel.setName("parentescoLabel"); // NOI18N

    codPessoaLabel.setText(resourceMap.getString("codPessoaLabel.text")); // NOI18N
    codPessoaLabel.setName("codPessoaLabel"); // NOI18N

    codAlunoLabel.setText(resourceMap.getString("codAlunoLabel.text")); // NOI18N
    codAlunoLabel.setName("codAlunoLabel"); // NOI18N

    rendaFamiliarDepoisLabel.setText(resourceMap.getString("rendaFamiliarDepoisLabel.text")); // NOI18N
    rendaFamiliarDepoisLabel.setName("rendaFamiliarDepoisLabel"); // NOI18N

    rendaFamiliarAntesLabel.setText(resourceMap.getString("rendaFamiliarAntesLabel.text")); // NOI18N
    rendaFamiliarAntesLabel.setName("rendaFamiliarAntesLabel"); // NOI18N

    jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
    jLabel1.setName("jLabel1"); // NOI18N

    jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Não", "Sim" }));
    jComboBox4.setName("jComboBox4"); // NOI18N

    binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, composicaoFamiliar1, org.jdesktop.beansbinding.ELProperty.create("${responsavel}"), jComboBox4, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
    bindingGroup.addBinding(binding);

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                .addComponent(masterScrollPane, javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(historicoFamiliarLabel, javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(codAlunoLabel)
                            .addComponent(codPessoaLabel)
                            .addComponent(jComboBox2, 0, 341, Short.MAX_VALUE)
                            .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(rendaFamiliarAntesLabel)
                            .addGap(65, 65, 65)
                            .addComponent(jLabel1))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(rendaFamiliarAntesField, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(parentescoLabel)
                        .addComponent(rendaFamiliarDepoisLabel)
                        .addComponent(numeroPessoasFamiliaLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(rendaFamiliarDepoisField, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE)
                        .addComponent(numeroPessoasFamiliaField, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE)
                        .addComponent(jComboBox3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(codAlunoLabel)
                .addComponent(parentescoLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(codPessoaLabel)
                .addComponent(numeroPessoasFamiliaLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(numeroPessoasFamiliaField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(rendaFamiliarAntesLabel)
                .addComponent(rendaFamiliarDepoisLabel)
                .addComponent(jLabel1))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(rendaFamiliarAntesField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(rendaFamiliarDepoisField, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(historicoFamiliarLabel)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(masterScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(68, 68, 68))
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap())
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(6, 6, 6)
            .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 411, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    bindingGroup.bind();
    }

    // Code for dispatching events from components to event handlers.

    private class FormListener implements java.awt.event.ActionListener {
        FormListener() {}
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (evt.getSource() == newButton) {
                jFParente.this.newButtonActionPerformed(evt);
            }
            else if (evt.getSource() == deleteButton) {
                jFParente.this.deleteButtonActionPerformed(evt);
            }
            else if (evt.getSource() == refreshButton) {
                jFParente.this.refreshButtonActionPerformed(evt);
            }
            else if (evt.getSource() == saveButton) {
                jFParente.this.saveButtonActionPerformed(evt);
            }
        }
    }// </editor-fold>//GEN-END:initComponents

    

    @SuppressWarnings("unchecked")
    private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
        entityManager.getTransaction().rollback();
        entityManager.getTransaction().begin();
        java.util.Collection data = query.getResultList();
        for (Object entity : data) {
            entityManager.refresh(entity);
        }
        list.clear();
        list.addAll(data);
    }//GEN-LAST:event_refreshButtonActionPerformed
    
    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        int[] selected = masterTable.getSelectedRows();
        List<sccpa.ComposicaoFamiliar> toRemove = new ArrayList<sccpa.ComposicaoFamiliar>(selected.length);
        for (int idx = 0; idx < selected.length; idx++) {
            sccpa.ComposicaoFamiliar c = list.get(masterTable.convertRowIndexToModel(selected[idx]));
            toRemove.add(c);
            entityManager.remove(c);
        }
        list.removeAll(toRemove);
    }//GEN-LAST:event_deleteButtonActionPerformed
    
    private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed
        sccpa.ComposicaoFamiliar c = new sccpa.ComposicaoFamiliar();
        entityManager.persist(c);
        list.add(c);
        int row = list.size() - 1;
        masterTable.setRowSelectionInterval(row, row);
        masterTable.scrollRectToVisible(masterTable.getCellRect(row, 0, true));
        Alunos oAluno = new Alunos();
        oAluno.setCodAluno(jFAluno.codAluno);
        composicaoFamiliar1.setCodAluno(oAluno);
    }//GEN-LAST:event_newButtonActionPerformed
    
    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        try {
            entityManager.getTransaction().commit();
            entityManager.getTransaction().begin();
        } catch (RollbackException rex) {
            rex.printStackTrace();
            entityManager.getTransaction().begin();
            List<sccpa.ComposicaoFamiliar> merged = new ArrayList<sccpa.ComposicaoFamiliar>(list.size());
            for (sccpa.ComposicaoFamiliar c : list) {
                merged.add(entityManager.merge(c));
            }
            list.clear();
            list.addAll(merged);
        }
    }//GEN-LAST:event_saveButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.util.List<sccpa.Alunos> alunosList;
    private javax.persistence.Query alunosQuery;
    private javax.swing.JLabel codAlunoLabel;
    private javax.swing.JLabel codPessoaLabel;
    private sccpa.ComposicaoFamiliar composicaoFamiliar1;
    private javax.swing.JButton deleteButton;
    private javax.persistence.EntityManager entityManager;
    private javax.swing.JLabel historicoFamiliarLabel;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JToolBar jToolBar1;
    private java.util.List<sccpa.ComposicaoFamiliar> list;
    private javax.swing.JScrollPane masterScrollPane;
    private javax.swing.JTable masterTable;
    private javax.swing.JButton newButton;
    private javax.swing.JTextField numeroPessoasFamiliaField;
    private javax.swing.JLabel numeroPessoasFamiliaLabel;
    private javax.swing.JLabel parentescoLabel;
    private java.util.List<sccpa.Pessoas> pessoasList;
    private javax.persistence.Query pessoasQuery;
    private javax.persistence.Query query;
    private javax.swing.JButton refreshButton;
    private javax.swing.JTextField rendaFamiliarAntesField;
    private javax.swing.JLabel rendaFamiliarAntesLabel;
    private javax.swing.JTextField rendaFamiliarDepoisField;
    private javax.swing.JLabel rendaFamiliarDepoisLabel;
    private javax.swing.JButton saveButton;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            public void run() {
                JFrame frame = new JFrame();
                frame.setContentPane(new jFParente());
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.pack();
                frame.setVisible(true);
            }
        });
    }
}
